﻿using System;
using System.Linq;
using Model;

namespace BLL
{
    public class Sys_ActionsInControllersInRoles_BLL
    {
        ExtendedDBModelContainer _db = new ExtendedDBModelContainer();

        public Sys_ActionsInControllersInRoles Get(Guid ActionId, Guid ControllerId, Guid RoleId)
        {
            return _db.Sys_ActionsInControllersInRoles.SingleOrDefault(a => a.ActionId.Equals(ActionId) && a.ControllerId.Equals(ControllerId) && a.RoleId.Equals(RoleId));
        }

        public void Insert(Guid ActionId, Guid ControllerId, Guid RoleId)
        {
            var item = new Sys_ActionsInControllersInRoles() { ActionId = ActionId, ControllerId = ControllerId, RoleId = RoleId };
            _db.Sys_ActionsInControllersInRoles.AddObject(item);
            _db.SaveChanges();
        }

        public void Delete(Guid ActionId, Guid ControllerId, Guid RoleId)
        {

            var item = Get(ActionId, ControllerId, RoleId);
            if (item != null)
            {
                _db.Sys_ActionsInControllersInRoles.DeleteObject(item);
                _db.SaveChanges();
            }
        }
    }
}
